package be.ipl.diavoloz.modele;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@Entity
@Table(schema="DIAVOLOZ", name="DEMONS")
public class Demons implements Serializable{

	private static final long serialVersionUID = -47337126128581579L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;
	
	@NotNull
	private String nom;
	
	@Enumerated(EnumType.STRING)
	private Couleur couleur;
	
	@ManyToOne
	private Partie partie;
	
	
	private boolean estPris = false;
	
	protected Demons(){
	}
	
	public Demons(String nom, Couleur couleur){
		this.nom = nom;
		this.couleur = couleur;
	}

	public boolean isEstPris() {
		return estPris;
	}

	public void setEstPris(boolean estPris) {
		this.estPris = estPris;
	}

	public String getNom() {
		return nom;
	}

	public Couleur getCouleur() {
		return couleur;
	}
	
	

	public Partie getPartie() {
		return partie;
	}

	public void setPartie(Partie partie) {
		this.partie = partie;
	}

	public int getId() {
		return id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((couleur == null) ? 0 : couleur.hashCode());
		result = prime * result + (estPris ? 1231 : 1237);
		result = prime * result + id;
		result = prime * result + ((nom == null) ? 0 : nom.hashCode());
		result = prime * result + ((partie == null) ? 0 : partie.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Demons other = (Demons) obj;
		if (couleur != other.couleur)
			return false;
		if (estPris != other.estPris)
			return false;
		if (id != other.id)
			return false;
		if (nom == null) {
			if (other.nom != null)
				return false;
		} else if (!nom.equals(other.nom))
			return false;
		if (partie == null) {
			if (other.partie != null)
				return false;
		} else if (!partie.equals(other.partie))
			return false;
		return true;
	}
}
